* This tests for trust-specific seasonality in casemix. This is the test discussed in footnote 31 (but no tables are displayed in the text or appendix)
clear all

use "$savedata/masterdata.dta", replace

keep if sample25==1
gen vol = vol25

cap drop *docfe* 
cap drop *pred_survive30*


* Predict mortality for each patients
reghdfe survive30 c.prevyear_cost c.lsoa_imdscore10 c.lsoa_wa_benefits c.sales c.prevyear_admit_em c.prevyear_admit_el, absorb(i.derv_age##i.sex i.black i.mixed i.chinese i.asian i.race_miss i.ynch* i.prevyear_stroke i.di1 i.di2 i.di3 i.di4 i.di5 i.shock i.arrest i.arythmia i.arthero, savefe) keepsingleton 
predict pred_survive30, xbd
egen std_pred_survive30 = std(pred_survive30)

xtreg pred_survive30 i.dow##i.admidate_mont##i.finyear i.dow#i.trust_num, fe i(hyid)

testparm i.dow#i.trust_num

putexcel set "$results/footnote31tests.xlsx", replace
putexcel A1 = "Variable"
putexcel B1 = "Coefficient"

putexcel A2 = "dow; dow"
matrix b = `r(p)'
putexcel B2 = matrix(b), rownames

xtreg pred_survive30 i.dow##i.admidate_mont##i.finyear i.dow#i.trust_num i.admidate_mont#i.trust_num, fe i(hyid)

testparm i.dow#i.trust_num

putexcel A3 = "dow, month; dow"
matrix b = `r(p)'
putexcel B3 = matrix(b), rownames

testparm i.admidate_mont#i.trust_num

putexcel A4 = "dow, month; month"
matrix b = `r(p)'
putexcel B4 = matrix(b), rownames

testparm i.dow#i.trust_num i.admidate_mont#i.trust_num

putexcel A5 = "dow, month; dow, month"
matrix b = `r(p)'
putexcel B5 = matrix(b), rownames

* Test for trust trends in hour of admission (exit from ED to inpatient departments)

xtreg pred_survive30 i.dow##i.admidate_mont##i.finyear i.exithour i.exithour#i.trust_num if exithour!=., fe i(hyid)

testparm i.exithour#i.trust_num

putexcel A6 = "exithour; exithour"
matrix b = `r(p)'
putexcel B6 = matrix(b), rownames
